'''
Data classes for actors
'''

from PyQt4 import QtCore
import os
from rgeSystem import *
from rgeSave import *
import rgeExtra
import rgeSprite
import rgeBase

#keys
ACTOR_SPRITES_KEY = "_sprites_loc"
ACTOR_HIDE_KEY = "_hide"
ACTOR_SIZE_KEY = "_size"
ACTOR_SPRITE_NAMES_KEY = "_sprites_names"

#indexes
#float vecs
ACTOR_SIZE_INDEX = 0

#bool vecs
ACTOR_HIDE_INDEX = 0

#string vecs
ACTOR_SPRITE_NAMES_INDEX = 0

#sprite vecs
ACTOR_SPRITES_INDEX = 0


class ActorData(rgeBase.BaseData):
    def __init__(self, NewName = "No_Name"):
        super(ActorData, self).__init__(NewName)
        self.addStandard(rgeExtra.SpriteVecItem("", ACTOR_SPRITES_KEY, ACTOR_SPRITES_INDEX))
        self.addStandard(rgeExtra.BoolVecItem(False, ACTOR_HIDE_KEY, ACTOR_HIDE_INDEX))
        self.addStandard(rgeExtra.FloatVecItem(1, ACTOR_SIZE_KEY, ACTOR_SIZE_INDEX, 1, [2]))
        self.addStandard(rgeExtra.StringVecItem("No Name", ACTOR_SPRITE_NAMES_KEY, ACTOR_SPRITE_NAMES_INDEX))

        self.setFilename(ACTOR_DIR + '/' + NewName + ACTOR_EXTENSION)

    def getSprite(self, Index):
        return self.getStandard(ACTOR_SPRITES_KEY).getValue([Index])

    def getSizeX(self):
        return self.getStandard(ACTOR_SIZE_KEY).getValue([0])

    def getSizeY(self):
        return self.getStandard(ACTOR_SIZE_KEY).getValue([1])

    def getSpriteName(self, Index):
        return self.getStandard(ACTOR_SPRITE_NAMES_KEY).getValue([Index])

    def getHide(self, Index):
        return self.getStandard(ACTOR_HIDE_KEY).getValue([Index])

    def getNumOfSprites(self):
        return self.getStandard(ACTOR_SPRITE_NAMES_KEY).getSize([])

    def setSizeX(self, NewSize):
        self.getStandard(ACTOR_SIZE_KEY).setValue([0], NewSize)
        self.edited()

    def setSizeY(self, NewSize):
        self.getStandard(ACTOR_SIZE_KEY).setValue([1], NewSize)
        self.edited()

    def flipHideSprite(self, Index, Value):
        self.getStandard(ACTOR_HIDE_KEY).setValue([Index], Value)
        self.edited()

    def setSprites(self, NewSprites, NewHide, NewNames):
        for i in range(len(NewSprites)):
            self.addSprite(NewSprites[i], NewNames[i], NewHide[i])

    def addSprite(self, SpriteFilepath, SpriteName, SpriteHide = False):
        self.getStandard(ACTOR_SPRITES_KEY).appendVecValue([], SpriteFilepath)
        self.getStandard(ACTOR_SPRITE_NAMES_KEY).appendVecValue([], SpriteName)
        self.getStandard(ACTOR_HIDE_KEY).appendVecValue([], SpriteHide)
        self.edited()

    def removeSprite(self, Index):
        self.getStandard(ACTOR_SPRITES_KEY).pop([Index])
        self.getStandard(ACTOR_SPRITE_NAMES_KEY).pop([Index])
        self.getStandard(ACTOR_HIDE_KEY).pop([Index])
        self.edited()
